﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LeHouse.Server.Dto;
namespace LeHouse.Server.Dal
{
    /// <summary>
    /// 图片表的DAL
    /// </summary>
    public class Collateral_SitePictureDAL : GenericBaseDAL<Collateral_SitePicture>
    {
        /// <summary>
        /// 根据报告号和图片的上传控件的地址去查询图片表有没该条记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public int SitePicturecount(Collateral_SitePicture s)
        {
            int C_projectcount;
            string sql = @"select count(SP_Pictureurl) from t_SitePicture  where P_ReportNumber =@P_ReportNumber and SP_Addr=@SP_Addr ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                //    p.Value =s.P_ReportNumber;
                    cmd.Parameters.Add(p);
                    var p1 = cmd.CreateParameter();
                    p1.ParameterName = "@SP_Addr";
                  //  p1.Value = s.SP_Addr;
                    cmd.Parameters.Add(p1);
                    C_projectcount = Convert.ToInt32(cmd.ExecuteScalar());
                }
                return C_projectcount;
            }
        }
        /// <summary>
        /// 根据图片的上传控件的地址去查询图片表该条记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public Collateral_SitePicture returnSP_pid(string SP_Addr)
        {
            Collateral_SitePicture munity = new Collateral_SitePicture();
            string sql = @"select * from t_SitePicture  where  SP_Addr=@SP_Addr ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p1 = cmd.CreateParameter();
                    p1.ParameterName = "@SP_Addr";
                    p1.Value =SP_Addr;
                    cmd.Parameters.Add(p1);
                    var reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            //munity.P_ReportNumber = reader["P_ReportNumber"].ToString();
                            //munity.SP_Addr = reader["SP_Addr"].ToString();
                            //munity.SP_Picturename = reader["SP_Picturename"].ToString();
                            //munity.SP_pid = Convert.ToInt64(reader["SP_pid"]);
                            //munity.SP_ptype = reader["SP_ptype"].ToString();
                            //munity.SP_Pictureurl = reader["SP_Pictureurl"].ToString();

                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
                return munity;
            }
        }
        /// <summary>
        /// 根据报告号查询图片表的所有的记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public List<Collateral_SitePicture> PictureShow(string s)
        {
            List<Collateral_SitePicture> lists = new List<Collateral_SitePicture>();
            string sql = @"select * from t_SitePicture  where P_ReportNumber =@P_ReportNumber  ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = s;
                    cmd.Parameters.Add(p);
                 
                    var reader = cmd.ExecuteReader();
                    try
                    {

                       
                        while (reader.Read())
                        {
                            Collateral_SitePicture munity = new Collateral_SitePicture();
                            //munity.SP_Picturename = reader["SP_Picturename"].ToString();
                            //munity.SP_Pictureurl = reader["SP_Pictureurl"].ToString();
                            //munity.SP_ptype = reader["SP_ptype"].ToString();
                            //munity.SP_Addr = reader["SP_Addr"].ToString();
                            lists.Add(munity);
                        }
                       
                    }
                    finally
                    {
                        reader.Close();
                    }
                    return lists;
                }
            }
        }
    
    }
}
